clear
set more off
cd "INSERT FILE PATH HERE"

use "datafolha.dta", clear

global controls = "wealth5 age female i.region i.partyid"

* Table C31
reg rc i.educ2 wealth5 age female i.region i.partyid i.race

* Figure 6
margins, at(educ2=(1 2 3 4) race=(1 2 3))
margins, at(educ2=(1 2 3 4) race=(1 2 3)) pwcompare
margins, at(educ2=(1 2 3 4) race=(1 2 3)) pwcompare
margins, at(educ2=(1 2 3 4) race=(1 2 3)) pwcompare

* Table C32
logit racialid2 i.educ2 $controls
logit racialid2 i.educ2 $controls i.race
logit racialid2 rc i.educ2 $controls i.race

* Figure 7
logit racialid2 rc i.educ2 $controls i.race
margins, at(rc=(0 1 2 3 4))
margins, at(rc=(0 1 2 3 4)) pwcompare

* Table C32
mlogit racialid3 i.educ2 $controls, base(2)
mlogit racialid3 i.educ2 $controls i.race, base(2)
mlogit racialid3 rc i.educ2 $controls i.race, base(2)

* Figure 8
mlogit racialid3 rc i.educ2 $controls i.race, base(2)
margins, at(rc=(0 1 2 3 4))
margins, at(rc=(0 1 2 3 4)) pwcompare predict(outcome(1))
margins, at(rc=(0 1 2 3 4)) pwcompare predict(outcome(2))
margins, at(rc=(0 1 2 3 4)) pwcompare predict(outcome(3))

* Figure C1
set level 90
mlogit racialid3 c.educ2 i.race $controls, base(2)
margins, dydx(educ2) at(race=(1 2 3))

mlogit racialid3 c.rc i.race i.educ2 $controls, base(2)
margins, dydx(rc) at(race=(1 2 3))

